<?php

require_once 'Pipes/Config.php';
require_once 'Pipes/Value/Template/CamelCapsToDatabase.php';
require_once 'Pipes/View.php';
require_once 'PipesImpl/FileSystem/Directory.php';

class Pipes_Generator_Start_Config
{
	private $_projectPath = null;
	private $_view = null;

	public function __construct(PipesImpl_FileSystem_Directory $root) {
		$this->_projectPath = $root;

		$config = new Pipes_Config(array('projects' => array('PipesCore')));
		$this->_view = new Pipes_View($config, 'GeneratorTemplates');

		$project = basename($this->_projectPath->toString());
		$this->_view->project = $project;
		$this->_view->generatingClass = __CLASS__;
		
		$dbName = new Pipes_Value_Template_CamelCapsToDatabase($project);
		$this->_view->dbName = $dbName;
	}

	public function create(array $options = array()) {
		$this->_view->options = $options;
		$configFilePath = $this->_projectPath->toString() . DIRECTORY_SEPARATOR . 'config.php';

		$fp = fopen($configFilePath, 'x+');
		fwrite($fp, str_replace('<\?php', '<?php', $this->_view->render('config')));
		fclose($fp);
	}
}
